home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / filbuf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  819 b   |  38 lines

  1. /*
  2.  * fill and process an input buffer
  3.  *    called only when fp->_cnt < 0
  4.  *
  5.  *    ++jrb    bammi@dsrgsun.ces.cwru.edu
  6.  */
  7.  
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <sys/types.h>
  12. #include <unistd.h>
  13.  
  14. int _filbuf(fp)
  15. FILE *fp;
  16. {
  17.     register unsigned int f;
  18.     register long got;
  19.     
  20.     f = fp->_flag;
  21.     if(f & _IORW) f = (fp->_flag |= _IOREAD);
  22.     if(!(f & _IOREAD) || (f & (_IOERR | _IOEOF)))
  23.     return(EOF);
  24.  
  25.     /* if this is stdin &  a tty, and stdout is line buffered, flush it */
  26.     if((fp == stdin) && (f & _IODEV) && (stdout->_flag & _IOLBF))
  27.     (void)fflush(stdout);
  28.  
  29.     if((got = lread(fp->_file, fp->_base, (long)fp->_bsiz)) <= 0)
  30.     {   /* EOF or error */
  31.     fp->_flag |= ((got == 0) ? _IOEOF : _IOERR);
  32.     return EOF;
  33.     }
  34.     fp->_cnt = got - 1;
  35.     fp->_ptr = fp->_base + 1;
  36.     return *(fp->_base);
  37. }
  38.